web/src/pages/inventory/[...inventoryId].astro

101 lines · 2714 bytes

  1---
  2
  3import Layout from '@layouts/Layout.astro';
  4import SavedServices from '@components/things/SavedServices.svelte';
  5import GetSharableLink from '@components/things/GetSharableLink.svelte';
  6
  7import { fetchData } from '@utils/fetch-data';
  8import Button from '@components/form/Button.astro';
  9import EditableTitle from '@components/form/EditableTitle.svelte';
 10import type { Category } from '../../types/Service';
 11
 12const categories = (await fetchData())?.categories || [] as Category[];
 13
 14export const prerender = false;
 15
 16const inventoryId = Astro.params.inventoryId || 'Inventory';
 17let cheekyLilError = '';
 18
 19function makeTitle(input: string): string {
 20  return (input.includes('_') ? input : `mystry_${input}`)
 21    .split('_')[1]
 22    .replace(/-/g, ' ')
 23    .replace(/\b\w/g, (match) => match.toUpperCase());
 24}
 25
 26const serviceList = await fetch(`https://awesome-privacy-share-api.as93.net/${inventoryId}`).then((res) => res.json()) || [];
 27
 28if (serviceList.error) {
 29  cheekyLilError = serviceList.error;
 30}
 31
 32---
 33
 34<Layout title="Saved Services">
 35  <main>
 36    <h2>{makeTitle(inventoryId)}</h2>
 37    {cheekyLilError && (
 38      <div class="error">
 39        <p class="oh-deary-me">An error occoured</p>
 40        <p class="what-the-fuck-happened">{cheekyLilError}</p>
 41        <p class="what-next">
 42          We're sorry about that.<br />
 43          Try going <a href="/">back home</a>,
 44          or <a href="https://github.com/Lissy93/awesome-privacy/issues/new/choose">raising a ticket</a> on
 45          GitHub.
 46        </p>
 47      </div>
 48    )}
 49    <SavedServices allData={categories} serviceList={serviceList} client:load />
 50    <div class="buttons">
 51      <p>Not found what you're looking for?</p>
 52      <Button url="/all">Browse Services</Button>
 53    </div>
 54  </main>
 55</Layout>
 56
 57<style lang="scss">
 58  main {
 59    margin: 0 auto 2rem auto;
 60    padding: 1rem;
 61    width: 1200px;
 62    max-width: calc(100% - 5rem);
 63    display: flex;
 64    justify-content: space-between;
 65    flex-direction: column;
 66    min-height: calc(100vh - 12rem);
 67    font-size: 1.25rem;
 68    h2 {
 69      font-family: "Lekton", sans-serif;
 70      font-weight: bold;
 71      font-size: 3rem;
 72      margin: 0;
 73      color: var(--accent-3);
 74    }
 75    .buttons {
 76      margin: 1rem auto;
 77      display: flex;
 78      flex-direction: column;
 79    }
 80    .error {
 81      text-align: center;
 82      font-size: 1.4rem;
 83      .oh-deary-me {
 84        font-size: 1.8rem;
 85        margin: 0.2rem auto;
 86      }
 87      .what-the-fuck-happened {
 88        color: var(--danger);
 89        margin: 0.2rem auto;
 90      }
 91      .what-next {
 92        font-size: 1rem;
 93        margin-top: 3rem;
 94        opacity: 0.6;
 95        a {
 96          color: var(--foreground);
 97        }
 98      }
 99    }
100  }
101</style>